<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>我的订单</title>
    <div th:include="Common/common :: head"></div>
    <script type="text/javascript">
        $(function (){
            $("#returnorder").click(function (){
                location.href="http://localhost:8080/games";
            })
            $(".df-btn").click(function (){
                var orderId=$(this).attr("orderid");
                swal({
                    title: "确定要删除该订单吗?",
                    text: "一旦删除无法撤销哟",
                    icon: "warning",
                    buttons: ["我再想想┭┮﹏┭┮", "确定删除！"],
                    dangerMode: true,
                    showCancelButton: true,
                })
                    .then((willDelete) => {
                        if (willDelete) {
                            $.ajax({
                                url:"http://localhost:8080/deleteorder",
                                type:"Get",
                                data:{orderId:orderId},
                                success:function (data){
                                    swal("该订单已经删除", {icon: "success",}).then(function (){
                                        location.href="http://localhost:8080/myorders";
                                    });
                                }
                            })
                        } else {
                            swal("想好了再点哟");
                        }
                    });
            });
        })
    </script>
</head>
<body>
<div id="main-wrapper">
    <!--Header section start-->
    <div th:include="Common/common :: header"></div>
    <!--Header section end-->
    <div class="container">
        <div class="row">
            <div class="col-md-12"><li><h1 style="color: red" class="font-weight-light">🛒Order🛒</h1></li></div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <table class="table table-hover" >
                    <tr>
                        <th>订单号</th>
                        <th>创建时间</th>
                        <th>订单总价</th>
                        <th>订单状态</th>
                        <th>订单详情</th>
                        <th>操作</th>
                    </tr>
                    <tr th:each="order:${orderlist}">
                        <th th:text="${order.orderId}"></th>
                        <th th:text="${order.Timechange()}"></th>
                        <th th:text="'￥'+${order.price}+元"></th>
                        <td th:if="${order.status!=2}" th:text="${order.status}==1?'已发货':'未发货'"></td>
                        <td th:if="${order.status==2}" th:text="已收货" style="color: red"></td>
                        <th class="link-arrow"><a th:href="@{/orderdetails(orderId=${order.orderId})}">订单详情</a></th>
                        <th>
                            <button class="df-btn" id="deleteOrder" th:orderid="${order.orderId}">删除</button>
                        </th>
                    </tr>
                </table>
                <center><h1 th:if="${orderlist.isEmpty()}" ><strong>Sorry!您暂时还没有订单(原来是穷逼,嘻嘻)</strong></li></h1></center><br><br>
                <button type="button" class="btn btn-primary btn-lg btn-block" id="returnorder" th:if="${orderlist.isEmpty()}">🛒点我购物捏🛒</button>
            </div>
        </div>
    </div>
    <div th:include="Common/common :: laster"></div>
</div>
</body>
</html>